package cn.jdx.controller;

import cn.jdx.entity.Items;
import cn.jdx.service.ItemsServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;


@Controller
@RequestMapping("/items")
public class ItemsController {
    @Resource(name = "itemsServiceImpl")
    private ItemsServiceImpl itemsService;

    //请求的参数一致
    @RequestMapping("/get1")
    public String get1(int id, Model model){
        Items items = itemsService.selectByPrimaryKey(id);
        System.out.println(items);
        model.addAttribute("items",items);
        String tips = "<br/>//请求的参数一致<br/>" +
                "    @RequestMapping(\"/get1\")<br/>" +
                "    public String get1(int id, Model model){<br/>" +
                "        Items items = itemsService.selectByPrimaryKey(id);<br/>" +
                "        System.out.println(items);<br/>" +
                "        model.addAttribute(\"items\",items);<br/>" +
                "        String tips = \"...\";<br/>" +
                "        model.addAttribute(\"tip\",tips);<br/>" +
                "        return \"show\";<br/>" +
                "    }";
        model.addAttribute("tip",tips);
        return "show";
    }

    //请求的参数不一致
    @RequestMapping("/get2")
    public String get2(@RequestParam(name = "num") int id, Model model){
        Items items = itemsService.selectByPrimaryKey(id);
        System.out.println(items);
        model.addAttribute("items",items);
        String tip = "<br/>//请求的参数不一致<br/>" +
                "    @RequestMapping(\"/get2\")<br/>" +
                "    public String get2(@RequestParam(name = \"num\") int id, Model model){<br/>" +
                "        Items items = itemsService.selectByPrimaryKey(id);<br/>" +
                "        System.out.println(items);<br/>" +
                "        model.addAttribute(\"items\",items);<br/>" +
                "        String tip = \"...\";<br/>" +
                "        model.addAttribute(\"tip\", tip);<br/>" +
                "        return \"show\";<br/>" +
                "    }";
        model.addAttribute("tip", tip);
        return "show";
    }



}
